using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using TEngine;
using UnityEngine;
using static UnityEngine.ParticleSystem;

namespace GameLogic
{
    public class PlayEffectCom : MonoBehaviour
    {
        [SerializeField]
        Vector3 m_Offset;
        [SerializeField]
        Vector3 m_Scale = Vector3.one;

        [SerializeField]
        float m_FlyToTargetDelay = 1;

        [SerializeField]
        GameObject m_Target;
        [SerializeField]
        string m_RenderLayer = "Top";
        bool m_IsFlyToTarget = false;

        void Start()
        {
        
        }
        GameObject m_CurObj;
        public void Play(string effectPath)
        {
            m_IsFlyToTarget = false;
            if (m_CurObj)
            {
                PoolManager.Instance.PushGameObject(m_CurObj);
            }

            m_CurObj = PoolManager.Instance.GetGameObject(effectPath);
            if(!m_CurObj)
                return;
            m_CurObj.transform.localScale = m_Scale;
            m_CurObj.transform.position = transform.position+m_Offset;
            var effect = m_CurObj.GetComponent<EffectCom>();
            effect.m_RenderLayer = m_RenderLayer;
            if(m_Target)
            {
                effect.m_TargetPosition = m_Target.transform.position;
                effect.m_HasTarget = true;
            }
            effect.m_FlyToTargetDelay = m_FlyToTargetDelay;
            effect.Play();
        }
    }
}
